﻿// VirtualFunc.cpp: 定义应用程序的入口点。
//

#include "Shape.h"
#include "VTShape.h"

int main()
{
    // C++ 语言实现的虚函数调用
    {
        auto triangle1 = Triangle(1);
        auto triangle2 = Triangle(2);
        auto circle = Circle();
        Shape* shapes[] = { &triangle1, &triangle2, &circle };

        for (auto shape : shapes)
        {
            shape->Print();
        }
    }

    // 编译器实现的虚拟函数的调用
    {
        Triangle_t triangle1;
        ConstructTriangle(&triangle1, 1);
        Triangle_t triangle2;
        ConstructTriangle(&triangle2, 2);
        Circle_t circle;
        ConstructCircle(&circle);
        VTShape* vtShapes[] = { (VTShape*)&triangle1, (VTShape*)&triangle2, (VTShape*)&circle };
        for (auto shape : vtShapes)
        {
            VTShapePrint(shape);
        }
    }

    return 0;
}